import { get, post, put, del } from '@/utils/request'

// 品牌相关的类型定义
export interface Brand {
  id: number
  bName: string
}

export interface BrandQueryParams {
  pageIndex: number
  pageSize: number
}

export interface BrandResponse {
  totalCount: number
  totalPages: number
  list: Brand[]
}

// API 响应类型
export interface ApiResponse<T> {
  code: number
  msg: string
  data: T
}

// 创建品牌的参数类型
export interface CreateBrandParams {
  bName: string
  id?: number
}

// 获取品牌列表
export const reqBrandList = () => {
  return get<ApiResponse<Brand[]>>('/api/Goods/GetBrandsList')
}

// 创建品牌
export const reqCreateBrand = (data: CreateBrandParams) => {
  return post<ApiResponse<number>>('/api/Goods/BrandAdd', data)
}

// 删除品牌
export const reqDeleteBrand = (id: number) => {
  return del<ApiResponse<number>>(`/api/Goods/DelBrand?id=${id}`)
}

//---------------------------------------------------------------

// 获取品牌详情
export const getBrandDetail = (id: number) => {
  return get<Brand>(`/api/brands/${id}`)
}

// 更新品牌
export const updateBrand = (id: number, data: Partial<Brand>) => {
  return put<Brand>(`/api/brands/${id}`, data)
}

// 更新品牌状态
export const updateBrandStatus = (id: number, status: number) => {
  return put<Brand>(`/api/brands/${id}/status`, { status })
}

// 批量删除品牌
export const deleteBrands = (ids: string) => {
  return del<ApiResponse<number>>(`/api/Goods/DelAllBrand?ids=${ids}`)
}

///api/Goods/DelBrand
//删除品牌

// 更新品牌排序
export const updateBrandSort = (id: number, sort: number) => {
  return put<Brand>(`/api/brands/${id}/sort`, { sort })
}

// 获取所有品牌（不分页）
export const getAllBrands = () => {
  return get<Brand[]>('/api/brands/all')
}
